﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Threading.Tasks;

namespace BLL
{
   public class Update
    {
       //修改模型信息
       public static int UpdateModel(string ID,string Name, string AdminDir, string WebDir, string TableName, string Remark)
       {
           #region 检查输入的合法性
           if (Name == "") return 0;
           if (AdminDir == "") return 0;
           if (WebDir == "") return 0;
           if (TableName == "") return 0;
           int id;
           try
           {
               id = Convert.ToInt32(ID);
           }
           catch
           {
               return 0;
           }

           #endregion

           #region 把数据组装成一个对象
           Models.Model model = new Models.Model();
           model.ID = id;
           model.Name = Name;
           model.AdminDir = AdminDir;
           model.WebDir = WebDir;
           model.TableName = TableName;
           model.Remark = Remark;
           #endregion

           return DAL.Update.UpdateModel(model);
       }
      /// <summary>
      /// 修改用户信息
      /// </summary>
       public static int UpdateUser(string ID, string Name, string Password, string RoleID, string UserEnabled)
       {
           #region 检查输入的合法性
           int id;
           try
           {
               id = Convert.ToInt32(ID);
           }
           catch
           {
               return 0;
           }
           if (Name == "") return 0;
           if (RoleID == "") return 0;
           if (UserEnabled == "") return 0;
           #endregion

           #region 把数据组装成一个对象
           Models.User user = new Models.User();
           user.ID = id;
           user.Name = Name;
           user.RoleID = Convert.ToInt32(RoleID);
           user.UserEnabled = Convert.ToBoolean(UserEnabled);
           string delim = "  ";
           string password = Password.Trim(delim.ToCharArray());
           if (password.Length<1)
           {
               user.Password = BLL.Find.FindUser(ID).Password;
           }
           else
           {
               user.Password = Utility.Tool.SHA256Encrypt(Password);
           }
           #endregion

           return DAL.Update.UpdateUser(user);
       }
       /// <summary>
       /// 修改角色信息
       /// </summary>
       public static int UpdateRole(string ID,string Name, string RoleInfoModelID, string RoleEnabled, string IsAdmin, string ModelAdmin, string UserAdmin, string RoleAdmin, string LogAdmin, string SystemAdmin, string ColumnAdmin, string FileAdmin, string  ContentAdmin)
       {
           #region 检查输入的合法性
           if (Name == "") return 0;

           int id;
           try
           {
               id = Convert.ToInt32(ID);
           }
           catch
           {
               return 0;
           }

           #endregion

           #region 把数据组装成一个对象
           Models.Role role = new Models.Role();
           role.ID = id;
           role.Name = Name;
           role.RoleInfoModelID = Convert.ToInt32(RoleInfoModelID);

           role.IsAdmin = Convert.ToBoolean(IsAdmin);
           role.ModelAdmin = Convert.ToBoolean(ModelAdmin);
           role.ColumnAdmin = Convert.ToBoolean(ColumnAdmin);
           role.ContentAdmin = ContentAdmin;
           role.UserAdmin = Convert.ToBoolean(UserAdmin);
           role.RoleAdmin = Convert.ToBoolean(RoleAdmin);
           role.FileAdmin = Convert.ToBoolean(FileAdmin);
           role.LogAdmin = Convert.ToBoolean(LogAdmin);
           role.SystemAdmin = Convert.ToBoolean(SystemAdmin);
           role.RoleEnabled = Convert.ToBoolean(RoleEnabled);
           #endregion

           return DAL.Update.UpdateRole(role);
       }
       // 修改栏目信息，传入栏目的各种信息
       public static int UpdateColumn(string ID, string Name, string ParentID, string ModelID,string ColumnLogo,string Remark)
       {
           #region 输入合法性检查
           if (Name == "") return 0;
           int id, PID, MID;
           try
           {
               id = Convert.ToInt32(ID);
               PID = Convert.ToInt32(ParentID);
               MID = Convert.ToInt32(ModelID);
           }
           catch
           {
               return 0;
           }
           #endregion

           #region 组装栏目成类的实例
           Models.Column column = new Models.Column();
           column.ID = id;
           column.Name = Name;
           column.ParentID = PID;
           column.ModelID = MID;
           column.ColumnLogo = ColumnLogo;
           column.Remark = Remark;
           #endregion

           return DAL.Update.UpdateColumn(column);
       }
       // 修改栏目顺序
       public static int UpdateSortColumn(string ID,  string ParentID, string OrderID)
       {
           #region 输入合法性检查
          ;
           int id, PID, OID;
           try
           {
               id = Convert.ToInt32(ID);
               PID = Convert.ToInt32(ParentID);
               OID = Convert.ToInt32(OrderID);
           }
           catch
           {
               return 0;
           }
           #endregion

           #region 组装栏目成类的实例
           Models.Column column = new Models.Column();
           column.ID = id;         
           column.ParentID = PID;
           column.OrderID = OID; 
           #endregion

           return DAL.Update.UpdateSortColumn(column);
       }
       // 更新文章模型内容
       public static int UpdateArticle(string ID, string ColumnID, string LastEditor, string Title, string Content, string UpdateDate, string Source, string Status)
       {
           #region 输入合法性检查
           if (Title == "") return 0;
           if (Content == "") return 0;
           if (Source == "") return 0;

           int id;
           int CID;
           DateTime DATE;
           bool STATUS;

           try
           {
               id = Convert.ToInt32(ID);
               CID = Convert.ToInt32(ColumnID);
               DATE = Convert.ToDateTime(UpdateDate);
               STATUS = Convert.ToBoolean(Status);
           }
           catch
           {
               return 0;
           }
           #endregion

           #region 把输入组装成类的实例
           Models.ModelArticle article = new Models.ModelArticle();
           article.ID = id;
           article.Title = Title;
           article.ColumnID = CID;
           article.UpdateDate = DATE;
           article.Content = Content;
           article.LastEditor = LastEditor;
           article.Source = Source;
           article.Status = STATUS;
           #endregion

           return DAL.Update.UpdateArticle(article);
       }
       // 更新单页模型内容
       public static int UpdateContent(string ID, string ColumnID, string LastEditor, string Title, string Content, string UpdateDate)
       {
           #region 输入合法性检查
           if (Title == "") return 0;
           if (Content == "") return 0;

           int id;
           int CID;
           DateTime DATE;

           try
           {
               id = Convert.ToInt32(ID);
               CID = Convert.ToInt32(ColumnID);
               DATE = Convert.ToDateTime(UpdateDate);
           }
           catch
           {
               return 0;
           }
           #endregion

           #region 把输入组装成类的实例
           Models.ModelContent content = new Models.ModelContent();
           content.ID = id;
           content.Title = Title;
           content.ColumnID = CID;
           content.UpdateDate = DATE;
           content.Content = Content;
           content.LastEditor = LastEditor;
           #endregion

           return DAL.Update.UpdateContent(content);
       }
       // 更新滑动图片轮播模型内容
       public static int UpdateSlider(string ID, string ColumnID, string LastEditor, string Title, string UpdateDate, string PictureAddress, string ArticleAddress, string Remark)
       {
           #region 输入合法性检查
           if (Title == "") return 0;
           if (PictureAddress == "") return 0;
         

           int id;
           int CID;
           DateTime DATE;
   

           try
           {
               id = Convert.ToInt32(ID);
               CID = Convert.ToInt32(ColumnID);
               DATE = Convert.ToDateTime(UpdateDate);
             
           }
           catch
           {
               return 0;
           }
           #endregion

           #region 把输入组装成类的实例
           Models.ModelSlider slider = new Models.ModelSlider();
           slider.ID = id;
           slider.Title = Title;
           slider.ColumnID = CID;
           slider.UpdateDate = DATE;
           slider.PictureAddress = PictureAddress;
           slider.ArticleAddress = ArticleAddress;
           slider.LastEditor = LastEditor;
           slider.Remark = Remark;
           #endregion

           return DAL.Update.UpdateSlider(slider);
       }
       // 更新友情链接模型内容
       public static int UpdateLink(string ID, string ColumnID, string LastEditor, string WebUrl, string UpdateDate, string WebName, string WebLogo)
       {
           #region 输入合法性检查
           if (WebUrl == "") return 0;
           if (WebName == "") return 0;


           int id;
           int CID;
           DateTime DATE;


           try
           {
               id = Convert.ToInt32(ID);
               CID = Convert.ToInt32(ColumnID);
               DATE = Convert.ToDateTime(UpdateDate);

           }
           catch
           {
               return 0;
           }
           #endregion

           #region 把输入组装成类的实例
           Models.ModelLink link = new Models.ModelLink();
           link.ID = id;
           link.WebUrl = WebUrl;
           link.ColumnID = CID;
           link.UpdateDate = DATE;
           link.WebName = WebName;
           link.WebLogo = WebLogo;
           link.LastEditor = LastEditor;
           #endregion

           return DAL.Update.UpdateLink(link);
       }
       // 更新办公文件链接模型内容
       public static int UpdateOfficeFile(string ID,string FileName,string FileEditor,string UploadTime, string UploadSource)
       {
           if (FileName == "") return 0;
           int id;
           DateTime DATE;
           try
           {
               id = Convert.ToInt32(ID);
               DATE = Convert.ToDateTime(UploadTime);

           }
           catch
           {
               return 0;
           }
           #region 把输入组装成类的实例
           Models.ModelOfficeFile File = new Models.ModelOfficeFile();
           File.ID = id;
           File.FileName = FileName;
           File.FileEditor = FileEditor;
           File.UploadTime = DATE;
           File.UploadSource = UploadSource;

           #endregion

           return DAL.Update.UpdateOfficeFile(File);
       }
    }
}
